use rpc::{RpcResult};

struct RpcContextTest;

trait DoRouterTest {
    fn execute(&mut self) -> RpcResult<()>;
}

trait RouterFactoryTest<'a> {
    fn parse(&self, context: &'a mut RpcContextTest) -> Box<dyn DoRouterTest + 'a>;
}

struct TestDoRouterTest<'a> {
    context: &'a mut RpcContextTest,
}

impl <'a> DoRouterTest for TestDoRouterTest<'a> {
    fn execute(&mut self) -> RpcResult<()> {
        Ok(())
    }
}

struct TestRouterFactory {}
impl <'a>RouterFactoryTest<'a> for TestRouterFactory {
    fn parse(&self, context: &'a mut RpcContextTest) -> Box<dyn DoRouterTest + 'a> {
        Box::new(TestDoRouterTest{context})
    }
}


/// 问题： 被应用的可变对象自动销毁了
#[test]
fn router_test() {
    let mut context = RpcContextTest{};
    let factory = TestRouterFactory {};
    let mut router = factory.parse(&mut context);
    router.execute().unwrap();
    // let mut c2 = &mut context;
}















trait RouterFactoryTest2 {
    fn parse(&mut self) -> Box<dyn DoRouterTest>;
}

struct TestRouterFactory2<'a> {
    context: &'a mut RpcContextTest
}

impl <'a>RouterFactoryTest2 for TestRouterFactory2<'a> {
    fn parse(&mut self) -> Box<dyn DoRouterTest> {
        let dd = TestDoRouterTest{context: self.context};
        // Box::new(dd)
        todo!()
    }
}
